#ifndef CLIENT_BOOK_H
#define CLIENT_BOOK_H
#include "baseptc.h"
#include "gps.h"
namespace protocal
{
    class ClientBook : public BasePtc
    {
    public:
    ClientBook()
    {
        this->source = CLIENT;
        this->command.cli_command = CLI_BOOK;
        this->size = sizeof(ClientBook);
    };


    public:
    char  userID[10];
    GPS startGPS;
    GPS endGPS;
    short waitingTime; //minutes
    public:
    int recv(int sock)
    {
        char buff[size];
        unsigned int recvsize = 0;
        unsigned int ret = 0;
        while(recvsize < this->size - sizeof(BasePtc))
        {
            ret = read(sock,buff+ sizeof(BasePtc) + recvsize,size);
            recvsize += ret;
        }
        ClientBook * tmp = (ClientBook *)buff;
        memcpy(this->userID,tmp->userID,sizeof(this->userID));
        this->startGPS = tmp->startGPS;
        this->endGPS = tmp->endGPS;
        this->waitingTime = tmp->waitingTime;
        //memcpy(this->startGPS,tmp->startGPS,sizeof(this->startGPS));
        //memcpy(this->endGPS,tmp->endGPS,sizeof(this->endGPS));
        //memcpy(this->waitingTime,tmp->waitingTime,sizeof(this->waitingTime));
         return recvsize;
    };
    int send(int sock)
     {
          return write(sock,this,sizeof(ClientBook));
     };
  
    };
}



#endif //CLIENT_BOOK_H 
